package com.gexiaobao.pigeon.ui.fragment.mine.organization.activity

import android.os.Bundle
import androidx.recyclerview.widget.LinearLayoutManager
import com.gexiaobao.pigeon.R
import com.gexiaobao.pigeon.app.base.BaseActivity
import com.gexiaobao.pigeon.app.ext.init
import com.gexiaobao.pigeon.app.ext.initFooter
import com.gexiaobao.pigeon.app.ext.loadListData
import com.gexiaobao.pigeon.app.ext.loadServiceInit
import com.gexiaobao.pigeon.app.ext.showLoading
import com.gexiaobao.pigeon.app.util.StatusBarUtil
import com.gexiaobao.pigeon.databinding.ActivityNumberOfPigeonDeliveredBinding
import com.gexiaobao.pigeon.ui.adapter.AdapterNumberOfPigeonDelivered
import com.gexiaobao.pigeon.viewmodel.OrgRaceViewModel
import com.kingja.loadsir.core.LoadService
import me.hgj.jetpackmvvm.ext.util.setOnclickNoRepeat

/**
 * @Author      : hxw
 * @Date        : 2024/7/20 14:01
 * @Describe    : 交鸽羽数
 */
class ActivityNumberOfPigeonDelivered : BaseActivity<OrgRaceViewModel, ActivityNumberOfPigeonDeliveredBinding>() {

    private val mAdapter: AdapterNumberOfPigeonDelivered by lazy { AdapterNumberOfPigeonDelivered(arrayListOf()) }
    private lateinit var loadsir: LoadService<Any>
    private var memberId = 0

    override fun initView(savedInstanceState: Bundle?) {
        StatusBarUtil.setTranslucentForImageView(this, 0, null)

        mDatabind.includeBar.tvTitle.text = getString(R.string.Number_of_pigeon)
        memberId = intent.getIntExtra("memberId", 0)

        mDatabind.includeList.swipeRecyclerView.init(LinearLayoutManager(this), mAdapter).let {
            it.initFooter {
                mViewModel.getLoftPigeonListByMemberId(false, memberId)
            }
        }

        //状态页配置
        loadsir = loadServiceInit(mDatabind.includeList.swipeRefreshLayout) {
            //点击重试时触发的操作
            onRefresh()
        }

        onRefresh()

        mDatabind.includeList.swipeRefreshLayout.init {
            onRefresh()
        }
    }

    private fun onRefresh() {
        loadsir.showLoading()
        mViewModel.getLoftPigeonListByMemberId(true, memberId)
    }

    override fun createObserver() {
        super.createObserver()
        mViewModel.orgMinePigeonResult.observe(this) {
            loadListData(it, mAdapter, loadsir, mDatabind.includeList.swipeRecyclerView, mDatabind.includeList.swipeRefreshLayout)
        }
    }

    override fun onBindViewClick() {
        super.onBindViewClick()
        setOnclickNoRepeat(mDatabind.includeBar.ivBack) {
            when (it) {
                mDatabind.includeBar.ivBack -> finish()
            }
        }
    }
}